﻿/*************************************************************************************
 * 文 件 名:   HK_MakeGroup
 * 
 * 描    述:   工具全局设置
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/8/30
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using UnityEditor;

namespace HKTools
{
    [InitializeOnLoad]
    public static class HK_ToolStates
    {
        //public const int SmartCopyPriority = 0;
        //public const int MakeGroupPriority = 1;
        //public const int FindReferencesPriority = 2;

        //public const int ReNameToolPriority = 13;
        //public const int RandomRotOrScalePriority = 14;
        //public const int DotweenEaseShowPriority = 15;
        //public const int CreateGoByPathPriority = 16;
        //public const int TagAndLayerViewPriority = 17;
        //public const int HierarchySearchPriority = 18;

        //public const int ReplaceByHKUIPriority = 100;
        //public const int TaskSystemPriority = 100;

        //public const int WebsitesPriority = 200;

        //public const int GlobalSettingPriority = 999;

        public static bool IsActiveSmartCopy = true;
        public static bool IsActiveMakeGroup = true;
        public static bool IsActiveHierarchyPro = true;
        public static bool IsActiveAutoSwitchToUTF8 = true;

        static HK_ToolStates()
        {
            IsActiveSmartCopy = EditorPrefs.GetBool("IsActiveSmartCopy", true);
            IsActiveMakeGroup = EditorPrefs.GetBool("IsActiveMakeGroup", true);
            IsActiveHierarchyPro = EditorPrefs.GetBool("IsActiveHierarchyPro", true);
            HK_HierarchyPro.ChangeState(IsActiveHierarchyPro);
            IsActiveAutoSwitchToUTF8 = EditorPrefs.GetBool("IsActiveAutoSwitchToUTF8", true);
            HK_AutoSwitchToUTF8.ChangeState(IsActiveAutoSwitchToUTF8);
        }
    }

    public class HK_GlobalSetting : EditorWindow
    {
        const int GlobalSettingPriority = 999;

        bool smartCopyState = false;
        bool makeGroupState = false;
        bool hierarchyProState = false;
        bool autoSwitchToUTF8State = false;

        [MenuItem("HKTools/Settings...", priority = GlobalSettingPriority)]
        static void ShowSettingWindow()
        {
            EditorWindow settingWindow = GetWindow<HK_GlobalSetting>("HK_GlobalSetting");
            settingWindow.Show();
        }

        void OnEnable()
        {
            smartCopyState = HK_ToolStates.IsActiveSmartCopy;
            makeGroupState = HK_ToolStates.IsActiveMakeGroup;
            hierarchyProState = HK_ToolStates.IsActiveHierarchyPro;
            autoSwitchToUTF8State = HK_ToolStates.IsActiveAutoSwitchToUTF8;
        }

        void OnGUI()
        {
            EditorGUILayout.Space(5);

            EditorGUILayout.LabelField("全局设置", EditorStyles.boldLabel);

            EditorGUILayout.Space(5);

            HK_ToolStates.IsActiveSmartCopy = EditorGUILayout.ToggleLeft("是否启用 Smart Copy", HK_ToolStates.IsActiveSmartCopy);

            if (smartCopyState != HK_ToolStates.IsActiveSmartCopy)
            {
                smartCopyState = HK_ToolStates.IsActiveSmartCopy;
                EditorPrefs.SetBool("IsActiveSmartCopy", HK_ToolStates.IsActiveSmartCopy);
            }

            EditorGUILayout.Space(5);

            HK_ToolStates.IsActiveMakeGroup = EditorGUILayout.ToggleLeft("是否启用 MakeGroup", HK_ToolStates.IsActiveMakeGroup);

            if (makeGroupState != HK_ToolStates.IsActiveMakeGroup)
            {
                makeGroupState = HK_ToolStates.IsActiveMakeGroup;
                EditorPrefs.SetBool("IsActiveMakeGroup", HK_ToolStates.IsActiveMakeGroup);
            }

            EditorGUILayout.Space(5);

            HK_ToolStates.IsActiveHierarchyPro = EditorGUILayout.ToggleLeft("是否启用 HierarchyPro", HK_ToolStates.IsActiveHierarchyPro);

            if (hierarchyProState != HK_ToolStates.IsActiveHierarchyPro)
            {
                hierarchyProState = HK_ToolStates.IsActiveHierarchyPro;
                HK_HierarchyPro.ChangeState(hierarchyProState);

                EditorPrefs.SetBool("IsActiveHierarchyPro", HK_ToolStates.IsActiveHierarchyPro);
            }

            EditorGUILayout.Space(5);

            HK_ToolStates.IsActiveAutoSwitchToUTF8 = EditorGUILayout.ToggleLeft("是否启用 AutoSwitchToUTF8", HK_ToolStates.IsActiveAutoSwitchToUTF8);

            if (autoSwitchToUTF8State != HK_ToolStates.IsActiveAutoSwitchToUTF8)
            {
                autoSwitchToUTF8State = HK_ToolStates.IsActiveAutoSwitchToUTF8;
                HK_AutoSwitchToUTF8.ChangeState(HK_ToolStates.IsActiveAutoSwitchToUTF8);

                EditorPrefs.SetBool("IsActiveAutoSwitchToUTF8", HK_ToolStates.IsActiveAutoSwitchToUTF8);
            }
        }
    }
}